/**
 * 
 */
package tabs;

import javax.faces.application.Application;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import org.richfaces.component.html.HtmlTab;
import org.richfaces.component.html.HtmlTabPanel;

/**
 * @author max
 *
 */
public class TabsBean {

	private HtmlPanelGrid	panelGrid;
	private Integer			numOfTabs;

	public Integer getNumOfTabs() {
		return numOfTabs;
	}

	public void setNumOfTabs(Integer numOfTabs) {
		this.numOfTabs = numOfTabs;
		//		System.out.println("numOfTabs==="+this.numOfTabs);
	}

	public TabsBean() {
	}

	public HtmlPanelGrid getPanelGrid() {
		return panelGrid;
	}

	public void setPanelGrid(HtmlPanelGrid panelGrid) {
		this.panelGrid = panelGrid;
	}

	public void createTabs(ActionEvent event) {
		FacesContext context = FacesContext.getCurrentInstance();
		Application application = context.getApplication();
		HtmlTabPanel tabPanel = (HtmlTabPanel) application
				.createComponent(HtmlTabPanel.COMPONENT_TYPE);
		tabPanel.setSwitchType("ajax");
		//		System.out.println("numOfTabs==="+this.numOfTabs);
		//		System.out.println("getNumOfTabs==="+this.getNumOfTabs());
		for (int i = 0; i < getNumOfTabs(); i++) {
			HtmlTab tab = (HtmlTab) application
					.createComponent(HtmlTab.COMPONENT_TYPE);
			tab.setName("tab" + i);
			tab.setLabel("Nice Tab # " + (i + 1));
			tabPanel.getChildren().add(tab);
		}
		panelGrid.getChildren().clear();
		panelGrid.getChildren().add(tabPanel);
	}
}
